package org.example.backend.repository;

import org.example.backend.entity.Animal;
import org.example.backend.entity.AnimalCategory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface AnimalRepository extends JpaRepository<Animal, Long> {
    List<Animal> findByCategory(AnimalCategory category);
    List<Animal> findByNameContaining(String name);
    Page<Animal> findByNameContainingAndCategoryId(String name, Long categoryId, Pageable pageable);
    
    @Query("SELECT a FROM Animal a WHERE a.category IN :categories")
    List<Animal> findByCategories(List<AnimalCategory> categories);
    
    @Query("SELECT a FROM Animal a ORDER BY a.popularity DESC")
    List<Animal> findByPopularity();
    
    @Query(value = "SELECT * FROM animals a WHERE " +
           "ST_Distance_Sphere(point(a.location_x, a.location_y), point(:longitude, :latitude)) <= :distance",
           nativeQuery = true)
    List<Animal> findNearbyAnimals(Double latitude, Double longitude, Double distance);
} 